﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServices;
using Zone;
using System.Diagnostics;//引入Process 类
using System.Reflection;//引入Assembly
using System.Threading;//需要用到mutex

namespace SmsSend
{
    public partial class login3 : Form
    {
        public static bool flag = false;
       
        public login3()
        {
            InitializeComponent();
        }

        /// <summary>
        /// webClient 控件载入页面，输入用户名和密码，返回页面html的字符串
        /// </summary>
        /// <param name="s1"></param>
        /// <param name="s2"></param>
        /// <param name="uriString"></param>
        /// <returns></returns>
        public string JspGBK(string s1, string s2, string uriString)
        {
            string postString = "username=" + s1 + "&password=" + s2 + "&act=1&Submit=";
            HttpClient webClient = new HttpClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            byte[] postData = Encoding.ASCII.GetBytes(postString);
            byte[] responseData = webClient.UploadData(uriString, "POST", postData);
            string srcString = Encoding.GetEncoding("GBK").GetString(responseData);        
            
            Init_GlobalSetting.CookContainer = webClient.Cookies;
            Init_GlobalSetting.CookCollection = CookieForEach.GetAllCookies(Init_GlobalSetting.CookContainer);

            SmsClass.SetWebBrowerCookie("http://192.168.1.11:8080/sms_pc/sms/jzsms.jsp", ref webBrowser1);                                                                  
            return srcString;

        }
        

        private void button1_Click(object sender, EventArgs e)
        {
      
            WebClient_LoadWeb wc = new WebClient_LoadWeb();
            string ss = JspGBK(textBox1.Text, textBox2.Text, "http://192.168.1.11:8080/sms_pc/login2.jsp");
            
            //判断登录是否成功
            if (ss.IndexOf("用户名不存在") > 0 || ss.IndexOf("密码不正确") > 0)
            {
                DebugNew.DebugMethod(ss);
                MessageBox.Show("验证错误！");
            }
            else
            {                               
                                                                       
            }          
        }       
    }
}
